#include<iostream>

using namespace std;

int check(string s) {
    string m[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int nmb = 0;
    int cnt = 0;
    for (int i=0; i<10; i++) {
        if (s == m[i]) {
            nmb = i;
            cnt ++;
            break;
        }
    }
    if (cnt == 0) {
        nmb = -1;
    }
    return nmb;
}

bool pr(int nmb2) {
    bool flag = true;
    for (int i = 2; i<nmb2; i++) {
        if (nmb2 % i == 0) {
            flag = false;
            break;
        }
    }
    return flag;
}

int main()
{
    string s2, a, b, c;
    int cnt2=0, p = 0, sum = 0, d = 0, e = 0;
    getline(cin, s2);
    for (int i = 0; i < s2.size(); i++) {
        if (s2[i] == ' ') {
            cnt2 ++;
        }
    }
    if (cnt2 == 2) {
        for (int i = 0; i < s2.size(); i++) {
            if (s2[i] == ' ') {
                a = s2.substr(0, i);
                p = i;
                break;
            }    
        }
        for (int q = 0; q < s2.size(); q++) {
            if (s2[q] == ' ' && q != p) {
                c = s2.substr(q+1);
                b = s2.substr(p+1, q-p-1);
            }
        }
        if (check(a) != -1 && check(b) != -1 && check(c) != -1 && check(a) != 0) {
            sum = check(a)*100 + check(b)*10 + check(c);
            if (pr(sum)) {
                cout << sum;
            }
            else {
                for (int i =sum+1; i < 998; i++) {
                    if (pr(i)) {
                        d = i;
                        break;
                    }
                }
                for (int z = sum; z > 2; z= z-1) {
                    if (pr(z)) {
                        e = z;
                        break;
                    }
                }
                if ((d - sum) >= (sum-e)) {
                    cout << e;
                }
                else {
                    cout << d;
                }
            }
        }
        else {
            cout << "Wrong input";
        }
    }
    else {
        cout << "Wrong input";
    }
}